home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / LSPREV.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  87 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lsprev.c    1.5 - 91/09/23" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8.  
  9. /* local headers */
  10. #include "lseq_.h"
  11.  
  12. /*man---------------------------------------------------------------------------
  13. NAME
  14.      lsprev - previous lseq record
  15.  
  16. SYNOPSIS
  17.      #include <lseq.h>
  18.  
  19.      int lsprev(lsp)
  20.      lseq_t *lsp;
  21.  
  22. DESCRIPTION
  23.      The lsprev function retreats the cursor of lseq lsp to the
  24.      previous record.  If the cursor is currently null, it will be
  25.      moved to the last record.  If the cursor is currently on the last
  26.      record, it will be moved to null.  If lsp is empty, the cursor
  27.      will remain set to null.
  28.  
  29.      lsprev will fail if one or more of the following is true:
  30.  
  31.      [EINVAL]       lsp is not a valid lseq pointer.
  32.      [LSELOCK]      lsp is not locked.
  33.      [LSENOPEN]     lsp is not open.
  34.  
  35. SEE ALSO
  36.      lscursor, lsfirst, lslast, lsnext.
  37.  
  38. DIAGNOSTICS
  39.      Upon successful completion, a value of 0 is returned.  Otherwise,
  40.      a value of -1 is returned, and errno set to indicate the error.
  41.  
  42. ------------------------------------------------------------------------------*/
  43. #ifdef AC_PROTO
  44. int lsprev(lseq_t *lsp)
  45. #else
  46. int lsprev(lsp)
  47. lseq_t *lsp;
  48. #endif
  49. {
  50.     /* validate arguments */
  51.     if (!ls_valid(lsp)) {
  52.         errno = EINVAL;
  53.         return -1;
  54.     }
  55.  
  56.     /* check if not open */
  57.     if (!(lsp->flags & LSOPEN)) {
  58.         errno = LSENOPEN;
  59.         return -1;
  60.     }
  61.  
  62.     /* check if not locked */
  63.     if (!(lsp->flags & LSLOCKS)) {
  64.         errno = LSELOCK;
  65.         return -1;
  66.     }
  67.  
  68.     /* move cursor */
  69.     if (lsp->clspos == NIL) {
  70.         lsp->clspos = lsp->lshdr.last;
  71.     } else {
  72.         lsp->clspos = lsp->clsrp->prev;
  73.     }
  74.  
  75.     /* read in new current record */
  76.     if (lsp->clspos == NIL) {
  77.         ls_rcinit(lsp, lsp->clsrp);
  78.     } else {
  79.         if (ls_rcget(lsp, lsp->clspos, lsp->clsrp) == -1) {
  80.             LSEPRINT;
  81.             return -1;
  82.         }
  83.     }
  84.  
  85.     return 0;
  86. }
  87.